package com.neuedu.curd.controller;


import com.neuedu.curd.entity.User;
import com.neuedu.curd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/json")
public class JsonController {
    @Autowired
    UserService userService;

    /**
     * http://localhost:8080/springmvc/json/getUser?id=1
     * @param id
     * @return
     */
    @RequestMapping("/getUser")
    @ResponseBody
    public User  toEdid(Integer id){

        User user = userService.queryById(id);
        return user;
    }



    @RequestMapping("map")
    @ResponseBody
    public Map getMap(Integer id){
        Map map = new HashMap();

        map.put("success",true);
        map.put("msg","访问成功");

        return map;
    }


    @RequestMapping("list")
    @ResponseBody
    public List getList(){
       List list = new ArrayList();

        for (int i = 0; i < 10; i++) {
            Map map = new HashMap();

            map.put("success",true);
            map.put("msg","访问成功");
            list.add(map);
        }
        return list;
    }


    @RequestMapping("list2")
    @ResponseBody
    public List getList2(){
        List<User> list = userService.list();
        return list;
    }




}
